(function($){
    $(document.body).ready(function(){
        $("#cargarFoto").fancybox({
            onComplete:configuraUploader
        });
    });
})(jQuery);

configuraUploader=function(){
    (function ($) {
        $('#file_upload').fileUploadUI({
            uploadTable: $('#files'),
            downloadTable: $('#files'),
            buildUploadRow: function (files, index) {
                return $('<tr><td>' + files[index].name + '<\/td>' +
                    '<td class="file_upload_progress"><div><\/div><\/td>' +
                    '<td class="file_upload_cancel">' +
                    '<button class="ui-state-default ui-corner-all" title="Cancel">' +
                    '<span class="ui-icon ui-icon-cancel">Cancel<\/span>' +
                    '<\/button><\/td><\/tr>');
            },
            buildDownloadRow: function (file) {
                var pathImg=app.imagesPath+'&pic='+file.name+':80';
                $("#TMP_PIC").val(file.name);
                return $('<tr><td><img width="100" height="100" src="'
                    +pathImg+'"/></td><td><button onclick="seleccionarFoto(\''
                    +file.name+'\')">Usar</button></td></tr>');
            }
        });
    })(jQuery);
	
}

seleccionarFoto=function(foto){
    (function($){
        $("#PICTURE_PATH").val(foto);
        $("#nuevafoto").html("");
        $("#nuevafoto").append('<img width="200" height="200" src="uploads/'+foto+'"/>');
        $.fancybox.close();
    })(jQuery);
}